<html>
<head><meta charset="utf-8"><title>inference on multiple conflicting traits in scope · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/inference.20on.20multiple.20conflicting.20traits.20in.20scope.html">inference on multiple conflicting traits in scope</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="181994055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/inference%20on%20multiple%20conflicting%20traits%20in%20scope/near/181994055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/inference.20on.20multiple.20conflicting.20traits.20in.20scope.html#181994055">(Nov 27 2019 at 06:37)</a>:</h4>
<p>Hi all. Has there ever been any thought with regard to inferring the correct trait when there are multiple in scope (using the same method name but different signatures)? My initial thought was that since the list of conflicting traits is already known, it should be possible to iterate through them and choose the trait that typechecks. This would only be the case if exactly one works, with the case for zero and multiple being status quo.</p>
<p>My use case for this is really the same as any other function/method overloading. But specifically, in my rewrite of the time crate, I have the <a href="https://time-rs.github.io/time/time/trait.NumericalDuration.html" target="_blank" title="https://time-rs.github.io/time/time/trait.NumericalDuration.html">NumericalDuration</a> and <a href="https://time-rs.github.io/time/time/trait.NumericalStdDurationShort.html" target="_blank" title="https://time-rs.github.io/time/time/trait.NumericalStdDurationShort.html">NumericalStdDurationShort</a> traits, which vary only in return type. It would be great to be able to have them both in scope and do <code>std::thread::sleep(5.seconds())</code> and have the compiler realize that only one trait in scope is capable of typechecking there. Right now, the workaround is to do <code>std::thread::sleep(5.std_seconds())</code>, which is...not as pretty.</p>
<p>Thoughts? I was thinking of writing an RFC, but not if there's zero chance of this happening.</p>



<a name="181997400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/inference%20on%20multiple%20conflicting%20traits%20in%20scope/near/181997400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/inference.20on.20multiple.20conflicting.20traits.20in.20scope.html#181997400">(Nov 27 2019 at 07:59)</a>:</h4>
<p>Wouldn't that allow for surprising breaking changes where if a crate changes the type of a function you're not calling but breaks your code because there's now ambiguity? Or is that already possible today?</p>



<a name="181998191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/inference%20on%20multiple%20conflicting%20traits%20in%20scope/near/181998191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/inference.20on.20multiple.20conflicting.20traits.20in.20scope.html#181998191">(Nov 27 2019 at 08:14)</a>:</h4>
<p>If I'm understanding you correctly, that would only happen if you already had two traits with the same function name in scope, which is currently always an error (without disambiguation). If you're referring to future changes, changing the function signature is a breaking change anyways.</p>



<a name="182388296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/inference%20on%20multiple%20conflicting%20traits%20in%20scope/near/182388296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/inference.20on.20multiple.20conflicting.20traits.20in.20scope.html#182388296">(Dec 02 2019 at 20:52)</a>:</h4>
<p>Anyone else have input on this, or should I create a pre-RFC over on internals?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>